<?php
/*
 * @Author: your name
 * @Date: 2020-11-16 16:32:43
 * @LastEditTime: 2020-12-07 15:44:34
 * @LastEditors: Please set LastEditors
 * @Description: 防火墙规则预览
 * @FilePath: /special/application/adminapiv3/model/NetfilterFirewallRuleModel.php
 */
namespace app\adminapiv3\model;

use app\common\exception\CustomException;
use app\common\definition\netfilter\FirewallRuleDefinition;
use think\Db;
use think\Exception;
use think\Model;

class NetfilterFirewallRuleModel extends Model
{
    /**
     * @name: 规则排序
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-11-16 16:35:38
     */
    public function ruleSort ($host_id, $ruleData)
    {
        $this->startTrans();
        try {
            $this->saveAll($ruleData);
            Db::name('host_learn_config')->where('host_id', $host_id)->update(['current_rule_group_status' => FirewallRuleDefinition::NORMAL_RULE_GROUP_STATUS]);
            $this->commit();
        } catch (Exception $e)
        {
            $this->rollback();
            Db::name('host_learn_config')->where('host_id', $host_id)->update(['current_rule_group_status' => FirewallRuleDefinition::SORT_FIAL_RULE_GROUP_STATUS]);
            throw new CustomException('排序失败:'. $e->getMessage(), 302);
        }
        
    }
}